package notwork;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoClient_1 {
    Socket socket=null;

    public TcpEchoClient_1(String serverIP,int port) throws IOException {
        socket=new Socket(serverIP,port);
    }

    public void start() throws IOException {
        Scanner scanner=new Scanner(System.in);

        try (InputStream inputStream=socket.getInputStream();
             OutputStream outputStream=socket.getOutputStream()){

            Scanner scannerNet=new Scanner(inputStream);
            PrintWriter writer=new PrintWriter(outputStream);

            while(true){
                String request=scanner.next();
                writer.println(request);
writer.flush();

String reponse=scannerNet.next();
                System.out.println(reponse);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        TcpEchoClient_1 tcpEchoClient_1=new TcpEchoClient_1("127.0.0.1",9090);
        tcpEchoClient_1.start();
    }

}
